FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:22-alpine3.20 AS builder
WORKDIR /app

# 复制依赖文件并安装
COPY package.json package-lock.json ./
RUN npm install --no-audit --no-fund

# 复制源代码
COPY . .

# 构建参数：前端API基础路径
ARG VITE_API_BASE_URL=/api
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL

# 执行前端构建
RUN npm run web:build

# 部署阶段
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:alpine3.20
WORKDIR /usr/share/nginx/html

# 复制构建产物
COPY --from=builder /app/dist/web ./

# 复制Nginx配置模板
COPY nginx.conf /etc/nginx/templates/default.conf.template

# 配置时区（与后端保持一致）
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
